package com.hq.fxh.No6UerSpace.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.hq.fxh.CustomerView.PopupWindow.PopupForList;
import com.hq.fxh.Modle.CityModle;
import com.hq.fxh.No5_User.Jianli.LAdapterCity;
import com.hq.fxh.R;

import java.util.List;

import static cn.jpush.android.api.JPushInterface.a.n;
import static cn.jpush.android.api.JPushInterface.a.o;
import static cn.jpush.android.api.JPushInterface.a.t;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/25
 * @Email xlwenhao1858@sina.com
 */


public class Fragment_citySelect extends Fragment {
    protected View rootView;
    protected ImageView toolbarImageBack;
    protected LinearLayout toolbarLayoutBack;
    protected TextView toolBarTvTitle;
    protected TextView toolBarTvMore;
    protected LinearLayout toolbarLayoutMore;
    protected LinearLayout toolbarContent;
    protected ListView popList;
    protected LinearLayout popupPingBi;
    private int type = 0;
    List<CityModle.DataBean> proData;
    List<CityModle.DataBean.CitysBean> cityData;
    CityCallBack cityCallBack;
    LAdapterCity adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.popup_list, null);
        initView(rootView);
        initData();

        return rootView;
    }

    public void setProData(List<CityModle.DataBean> proData, int type) {
        this.proData = proData;
        this.type = type;
        adapter.setType(0);
        adapter.setProData(proData);
        adapter.notifyDataSetChanged();
    }

    public void setCityData(List<CityModle.DataBean.CitysBean> cityData, int type) {
        this.cityData = cityData;
        this.type = type;
        if (adapter == null) {
            adapter = new LAdapterCity();
            adapter.setType(type);
            adapter.setCityData(cityData);
            popList.setAdapter(adapter);
        } else {
            adapter.setCityData(cityData);
            adapter.notifyDataSetChanged();
        }

    }

    public void setCityCallBack(CityCallBack cityCallBack) {
        this.cityCallBack = cityCallBack;
    }

    private void initData() {


            toolBarTvTitle.setText("选择地区");
            adapter = new LAdapterCity();
            adapter.setType(0);
            adapter.setProData(proData);
            popList.setAdapter(adapter);




        popList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                cityCallBack.selectCall(i, adapterView.getItemAtPosition(i));
            }
        });
    }


    private void initView(View rootView) {
        toolbarImageBack = (ImageView) rootView.findViewById(R.id.toolbar_image_back);
        toolbarLayoutBack = (LinearLayout) rootView.findViewById(R.id.toolbar_Layout_back);
        toolBarTvTitle = (TextView) rootView.findViewById(R.id.toolBar_tv_Title);
        toolBarTvMore = (TextView) rootView.findViewById(R.id.toolBar_tv_More);
        toolbarLayoutMore = (LinearLayout) rootView.findViewById(R.id.toolbar_Layout_More);
        toolbarContent = (LinearLayout) rootView.findViewById(R.id.toolbar_Content);
        popList = (ListView) rootView.findViewById(R.id.pop_list);
        popupPingBi = (LinearLayout) rootView.findViewById(R.id.popup_PingBi);
    }


    public interface CityCallBack {

        void selectCall(int position, Object data);
    }


    public static Fragment_citySelect newInstance(int type) {

        Bundle args = new Bundle();
        args.putInt("type",type);

        Fragment_citySelect fragment = new Fragment_citySelect();
        fragment.setArguments(args);
        return fragment;
    }


}
